<?php

function curl_get($durl) {
  $t = parse_url($durl);
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL,$durl);
  curl_setopt($ch, CURLOPT_HEADER, false);  
  curl_setopt($ch, CURLOPT_TIMEOUT,5);
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  curl_setopt($ch, CURLOPT_REFERER, "http://$t[host]/");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 // curl_setopt($ch, CURLOPT_RANGE, 1-100);
  $r = curl_exec($ch);
  curl_close($ch);
  return $r;
}


function curl_get_montior_type ($Machine_sn) {

//$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id=WS70087123');
$page = curl_get( 'http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id='.$Machine_sn);

$start = strstr($page,"litMachineName_LK");
$start_n = strpos($start,"span");
//echo $start_n."****";

$result = substr($start,40,($start_n-42));

//$result = substr($start,0,($start_n+100));

 //$lines_string=implode('',$arr);
 
 
 $result = str_replace("+"," ",$result);
 return urldecode($result);
//echo $result;
}



?>



<!DOCTYPE html>
<html>

<?php  //echo error_reporting(0); 		 ?>

	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	
<style type="text/css">
td.tabval {font-family: Courier New;}
</style>

	
	<script  type ="text/javascript" src="./1.js">
	

	
	</script>
	
	
	
	  <script type="text/javascript" language="javascript" src="./sn.js" >    </script>
	
	</head>


	<?php
	//echo '******************';
	//echo $_REQUEST['hidden_sn'];
			$filepath="./aa.sqlite3";

			$db=new SQLite3($filepath); //打开此路径数据库文件

			$sql="select '0000000000000'"; //查询记录
	?>
			
	<?php
	
			error_reporting(E_ALL); 
			if(isset($_REQUEST['snpn']) && !empty($_REQUEST['snpn'])) 
			{  
			$hidden_snpn=$db->escapeString(@$_REQUEST['snpn']);
			$hidden_sn=$db->escapeString(substr($hidden_snpn,0,10));
			$hidden_pn=$db->escapeString(substr($hidden_snpn,10,8));
			}
			else
			{
			$hidden_sn=$db->escapeString(@$_REQUEST['hidden_sn']);
			$hidden_pn=$db->escapeString(@$_REQUEST['hidden_pn']);
			}
			$hidden_mo=$db->escapeString(@$_REQUEST['hidden_mo']);
			$hidden_lucky=$db->escapeString(@$_REQUEST['hidden_lucky']);
			
			
			//echo "aaa@@@".$hidden_sn.$hidden_pn;
			
			
			
			/*
			//test code
			if ($hidden_pn=="") {   
			$results = $db->query("select 1  from pn where pn = ".$hidden_pn);
			$res = $results->fetchArray(SQLITE3_ASSOC);
			} 
				*/
						
			//$results =$db->query("select 1  from pn where pn = ".$hidden_pn);
			
	?>
	
	 
	 
	
	<body onload="JavaScript:(document.getElementById('input_sn_id')).focus();">

	<?php  //echo error_reporting(0); 		 ?>
	
	
	<form action="<?php if ($res[1]=="1") echo "./sqlite3.php"; else echo "./pn1.php";  ?>" name="formAddress" id="formAddress" method="post">
		<input hidden="hidden" name="example" id="example" type="text"  style="display:none;"/>
		<input readonly="readonly" name="hidden_sn" id="hidden_sn" type="text"  style="display:none;"/>
		<input readonly="readonly" name="hidden_pn" id="hidden_pn" type="text"  style="display:none;"/>
		<input readonly="readonly" name="hidden_mo" id="hidden_mo" type="text"  style="display:none;"/>
		<input readonly="readonly" name="hidden_lucky" id="hidden_lucky" type="text"  style="display:none;"/>
		<input readonly="readonly" name="hidden_monitor" id="hidden_monitor" type="text"  style="display:none;"/>
		<input type="submit" name="hidden_submit" id="hidden_submit" value="提交" style="display:none;" />

	</form>

	<?php
	//	echo	"###$$$".$res[1];
	//	echo "@@@"; if ($res[1]=="1") echo "good";
	?>

	
<?php	
		
		if(isset($_REQUEST['snpn']) && !empty($_REQUEST['snpn'])) 
		{	
			if($hidden_sn!="")
			{	echo $hidden_sn;
				$db->query("INSERT INTO sn (s_t,sn,pn,mo,lucky,datetime) VALUES('M','$hidden_sn','$hidden_pn','$hidden_mo','$hidden_lucky',datetime('now','+8 hour'));)");
			}	
		}
		else
		{
			if($hidden_sn!="")
			{	echo $hidden_sn;
				$db->query("INSERT INTO sn (s_t,sn,pn,mo,lucky,datetime) VALUES('P','$hidden_sn','$hidden_pn','$hidden_mo','$hidden_lucky',datetime('now','+8 hour'));");
			}	
		}
		//end if 
		
			

			if(@$_REQUEST['action']=="del")
			{
				$db->query("DELETE FROM sn WHERE id=".round($_REQUEST['id']));
			}
		
	?>
	
	
	



	
	<input id="input_sn_id" input="text" style="ime-mode:disabled" size="50" name="input_sn" onkeydown="noPermitInput(event)" /> 
	

<?php


$results = $db->query("SELECT * from sn ");


?>
<table border="1px" cellpadding=0 cellspacing=0>


<?php
$sqlite_sql = "SELECT 1 FROM montior  ;";
$result=$db->query($sqlite_sql);
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{$i++;} $sum_line = $i;
	
$sqlite_sql = "SELECT 1 FROM montior_groupbytype  ;";
$result=$db->query($sqlite_sql);
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{$i++;} $sum_type = $i;	
	
	
		echo "<tr valign='bottom'>";
		echo "<td bgcolor='#fb7922' colspan='1'><img src=img/blank.gif width='1' height='8'></td>";
	//	echo "<td bgcolor='#fb7922' colspan='1'><img src=img/blank.gif width='1' height='8'></td>";
        echo "<td bgcolor='#fb7922' colspan='1'><img src=img/blank.gif width='1' height='8'>".
			"<a href='./montior_type_all.php' >".
			"共计&nbsp;".			$sum_type.			"&nbsp;种".
			"</a>".
			"</td>";
		echo "<td bgcolor='#fb7922' colspan='8'><img src=img/blank.gif width='1' height='8'>".
			"共计&nbsp;".			$sum_line.			"&nbsp;行".
			"</td>";
			
        echo "</tr>";

?>








<tr bgcolor=#f87820>
<td><img src=img/blank.gif width=40 height=25></td>
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  type		</b></td>
<!--
<td class=tabhead><img src=img/blank.gif width=40 height=6><br><b>  S_T		</b></td>
-->
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  sn		</b></td>

<!--
<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  pn   		</b></td>


<td class=tabhead><img src=img/blank.gif width=100 height=6><br><b>  mo     	</b></td>
<td class=tabhead><img src=img/blank.gif width=120 height=6><br><b>  lucky      	</b></td>

<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
-->
<td class=tabhead><img src=img/blank.gif width=80 height=6><br><b>     		</b></td>
<td class=tabhead><img src=img/blank.gif width=50 height=6><br><b>      		</b></td>
<td><img src=img/blank.gif width=10 height=25></td>
</tr>



<?php

$result=$db->query("SELECT * FROM montior;");
	
	$i=0;
	while( $row=$result->fetchArray(SQLITE3_ASSOC) )
	{
		if($i>0)
		{
			//echo "<tr valign='bottom'>";
			//echo "<td bgcolor='#ffffff'			background='img/strichel.gif' colspan='6'><img src=img/blank.gif width='1' height='1'></td>";
			//echo "</tr>";
		}
		echo "<tr valign='center'>";
//		echo "<td class='tabval'><img src=img/blank.gif width=10 height=20></td>";
		echo "<td class='tabval'><b>".htmlspecialchars($row['id'])."</b></td>";
		
		/*
			if (empty($row['type']))
		{
			
		$montior_type = curl_get_montior_type($hidden_sn);
		

		$s_pl_sql = "UPDATE montior SET montior.type = '".$montior_type."' WHERE montior.sn = '".$row['sn']."';"; 
		$s_pl_sql = "INSERT INTO montior (sn,type) VALUES('".$row['sn']."','".$montior_type."');";
	
		$db->query($s_pl_sql);
		
		echo "<script language='javascript' type='text/javascript'>";
		//echo "window.location.reload(); ";
		echo "</script>";

		
		}
		*/
		
		
		
		
		
		echo "<td class='tabval'>"
				."<a href='./montior_type.php?type="
				.htmlspecialchars($row['type'])
				."'>"
				.htmlspecialchars($row['type'])
				."</a>"
				."&nbsp;</td>";
		
		//echo "<td class='tabval'>".htmlspecialchars($row['s_t'])."&nbsp;</td>";
		echo "<td class='tabval'>"
				."<a href='http://support1.lenovo.com.cn/lenovo/wsi/usercenter/computersearch/StandardMyComputerSearch.aspx?id="
				.htmlspecialchars($row['sn'])
				."'>"
				.htmlspecialchars($row['sn'])
				."</a>"
				."&nbsp;</td>";
		
		
		
		
		echo "<td class='tabval' style='color:#f00'>"
				."<a href='./pn_info.php?pn="
		//		.htmlspecialchars($row['pn'])
				."&hidden_sn="
				.htmlspecialchars($row['sn'])
				."'>"
		//		.htmlspecialchars($row['pn'])
				."</a>"
				."&nbsp;</td>";
				
		//echo "<td class='tabval'>".htmlspecialchars($row['mo'])."&nbsp;</td>";
		//echo "<td class='tabval'>".htmlspecialchars($row['lucky'])."&nbsp;</td>";
		//echo "<td class='tabval'>".htmlspecialchars($row['gc'])."&nbsp;</td>";
		//echo "<td class='tabval'>".htmlspecialchars($row['montior'])."&nbsp;</td>";

		echo "<td class='tabval'><a onclick=\"return confirm('"."abcdefg"."');\" href='sqlite3_1.php?action=del&id=".$row['id']."'><span class='red'>["."del"."]</span></a></td>";
		echo "<td class='tabval'></td>";
		echo "</tr>";
		$i++;

	}

	echo "<tr valign='bottom'>";
        echo "<td bgcolor='#fb7922' colspan='11'><img src=img/blank.gif width='1' height='8'></td>";
        echo "</tr>";

		
		$db->close(); //关闭


?>
	</table>
	
	<iframe src="./get_montior_type.php" height="20px" width="100%" ></iframe>

			<script  type ="text/javascript" >
			
			
			
			</script>
	
	</body>
</html>